module main;

import std.stdio;
import std.stdint;
import std.getopt;
import isa;

immutable VERSION = "1.0.0";

string toString(E)(E val) if (is(E == enum))
{
	foreach (s; __traits(allMembers, E))
	{
		if (val == mixin("E."~s)) return s;
	}
	return null;
}


int main(string [] args)
{
	bool bUsage = false;
	string isaListFile;

	getopt(args,
	       "help|usage|h|?", &bUsage,
			"list", &isaListFile
	       );

	if (bUsage) {
		usage();
		return 0;
	}

	auto instr8_1 = Instruction!uint16_t("cli",5,InstructionClass.Bitmanip,0,0x94f8,0xffff);
	writefln("Instruction: %s Bits: %d  Class: %s", instr8_1.name, instr8_1.bits, toString(instr8_1.ic));
	writefln("--> Backing: %s  Code: 0b%b (0x%x)", instr8_1.code.stringof,instr8_1.code,instr8_1.code);
	writefln("--> Bitmask: 0b%b (0x%x)", instr8_1.mask, instr8_1.mask);

	banner();
	startInteractive();


	return 0;
}

void startInteractive()
{

}

void banner()
{
	writeln("isgen v", VERSION);
	writeln("Instruction Set Generator");
	writeln("Copyright 2013 Open Design Strategies, LLC");
	writeln("100% Hand-made Open Source Software");
	writeln("");
}

void usage()
{
	banner();
	writeln("isgen [options]");
	writeln("where [options] are as follows:");
	writeln("--list <ISA file>        Lists an instruction set architecture");
	writeln("-h, -?, --help           Displays this help listing");

}